import {OrderModelInterface} from "../../../../net/instance/CommenModelInstance";
import OrderStoreInstance from "../../../../store/modules/order";
import toast from "../../../common/ToastProxy";
import {Actions} from "react-native-router-flux";

export interface FeatureBtnInterface {
    text: string,
    onPress: (order: OrderModelInterface, callback?: any) => () => void

}

function cancelOrder(order: OrderModelInterface, callback) {
    return async () => {
        await OrderStoreInstance.deleteOrder(order.id);
        toast("取消成功！", callback);
    }
}

function confirmReceipt(order: OrderModelInterface, callback) {
    return async () => {
        //修改订单状态为已签收
        await OrderStoreInstance.changeOrderStatus(OrderStatus.ORDER_COMPLETED, order.id);
        toast("签收成功！", callback);
    }
}

function goEvaluation(order: OrderModelInterface, callback) {
    return () => {
        callback();
    }
}

function checkBill(order: OrderModelInterface, callback) {
    return async () => {
        //设置待支付订单
        OrderStoreInstance.setSelectedOrderId(order);
        Actions.push("PayWay");
    }
}


const WAIT_PAY = [{
    text: "取消订单", onPress: cancelOrder
}, {
    text: "去付款", onPress: checkBill
}];
const WAIT_RECEIPT = [{
    text: "确认收货", onPress: confirmReceipt
}];
const ORDER_COMPLETED = [{
    text: "去评价", onPress: goEvaluation
}];
export {
    WAIT_PAY, WAIT_RECEIPT, ORDER_COMPLETED
}

export function getStatusLabel(status: number) {
    switch (status) {
        case 1:
            return "待付款";
        case 2:
            return "待收货";
        case 3:
            return "已收货";
    }
}

enum OrderStatus {
    WAIT_PAY = 1, WAIT_RECEIPT = 2, ORDER_COMPLETED = 3, EVALUATION_COMPLETED = 4
}